package se.cambio.system.rms.facade.impl;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import se.cambio.system.rms.bo.HospitalBo;
import se.cambio.system.rms.bo.impl.HospitalBoImpl;
import se.cambio.system.rms.dao.HospitalDao;
import se.cambio.system.rms.dto.HospitalDto;
import se.cambio.system.rms.entity.Hospital;
import se.cambio.system.rms.facade.HospitalFacade;

public class HospitalFacadeImpl implements HospitalFacade {
	HospitalBo hospitalBo;
	
	public void setHospitalBo(HospitalBo hospitalBo) {
		this.hospitalBo = hospitalBo;
	}
	
	public void createHospital(HospitalDto hospitalDto) {
		ApplicationContext appContext = new ClassPathXmlApplicationContext("resources/spring/config/BeanLocations.xml");
		
	    HospitalBo hospitalBo = (HospitalBo)appContext.getBean("hospitalBo");
	    
		Hospital hospital_new = new Hospital();
		hospital_new.setActive((long)1);
		hospital_new.setAddress(hospitalDto.getAddress());
		
		Calendar currentDate = Calendar.getInstance();
		SimpleDateFormat formatter= new SimpleDateFormat("yyyy/MMM/dd");
		String dateNow = formatter.format(currentDate.getTime());
		
		hospital_new.setCreated(dateNow);
		hospital_new.setCreator("admin");
		hospital_new.setId(hospitalDto.getId());
		hospital_new.setLatest((long)1);
		hospital_new.setName(hospitalDto.getName());
		
		hospitalBo.save(hospital_new);
	}

	public void deleteHospital(HospitalDto hospitalDto) {
	}

	public void editHospital(HospitalDto hospitalDto) {
	}

}
